package com.phelon.epdm;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.commons.lang.StringUtils;

import com.phelon.Global.AS400.Factory;

/**
 * @author pdanfy
 */

public class ItemRevisionC {
	public static void main(String[] args) {
		ItemRevisionC testRev = new ItemRevisionC("A  ", "ASP9802536", "      ");
		try {
			testRev.retrieveRecord("7T");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.exit(0);
	}
	private String site;
	private String item;
	private String revision;
	private String accountNumber;
	private String allowableDaysEarly;
	private String alphaFactor;
	private String buyer;
	private String extendedDescription1;
	private String extendedDescription2;
	private String nature;
	private String preApprovedItem;
	private String purchasePrice;
	private String purchasedItemCommodityClass;
	private String receiptRequired;
	private String shipVia;
	private String tolerancePercentReceivingNegative;
	private String tolerancePercentReceivingPositive;
	private String weightedDeliveryPercent;
	private String weightedEarlyDeliveryPercent;
	private String weightedLateDeliveryPercent;
	private String weightedLeadTimePercent;
	private String weightedOvershipPercent;
	private String weightedPricePercent;
	private String weightedQualitiyPercent;
	private String weightedUndershipPercent;

	
	public ItemRevisionC(String site, String item, String revision) {
		this.site = site;
		this.item = item;
		this.revision = revision;
	}


	public String getAccountNumber() {
		return accountNumber;
	}


	public String getAllowableDaysEarly() {
		return allowableDaysEarly;
	}


	public String getAlphaFactor() {
		return alphaFactor;
	}


	public String getBuyer() {
		return buyer;
	}


	public String getExtendedDescription1() {
		return extendedDescription1;
	}


	public String getExtendedDescription2() {
		return extendedDescription2;
	}


	public String getItem() {
		return item;
	}


	public String getNature() {
		return nature;
	}


	public String getPreApprovedItem() {
		return preApprovedItem;
	}


	public String getPurchasedItemCommodityClass() {
		return purchasedItemCommodityClass;
	}


	public String getPurchasePrice() {
		return purchasePrice;
	}


	public String getReceiptRequired() {
		return receiptRequired;
	}


	public String getRevision() {
		return revision;
	}


	public String getShipVia() {
		return shipVia;
	}


	public String getSite() {
		return site;
	}


	public String getTolerancePercentReceivingNegative() {
		return tolerancePercentReceivingNegative;
	}


	public String getTolerancePercentReceivingPositive() {
		return tolerancePercentReceivingPositive;
	}


	public String getWeightedDeliveryPercent() {
		return weightedDeliveryPercent;
	}


	public String getWeightedEarlyDeliveryPercent() {
		return weightedEarlyDeliveryPercent;
	}


	public String getWeightedLateDeliveryPercent() {
		return weightedLateDeliveryPercent;
	}


	public String getWeightedLeadTimePercent() {
		return weightedLeadTimePercent;
	}


	public String getWeightedOvershipPercent() {
		return weightedOvershipPercent;
	}


	public String getWeightedPricePercent() {
		return weightedPricePercent;
	}


	public String getWeightedQualitiyPercent() {
		return weightedQualitiyPercent;
	}


	public String getWeightedUndershipPercent() {
		return weightedUndershipPercent;
	}


	public void retrieveRecord(String fromEnv) throws SQLException {
		String fileEnv = " ";
		if (fromEnv == "7M") { 
			fileEnv = " ";
		} else {
			fileEnv = fromEnv.substring(1);
		}
		StringBuilder sql = new StringBuilder("SELECT * FROM AMFLIB").append(fileEnv)
				.append(".ITMRVCL0 WHERE ITNOAW = '").append(
				item).append("' and STIDAW = '").append(site).append(
				"' and ITRVAW = '").append(revision).append("'");
		Connection conn = Factory.getConnection();
		Statement st = conn.createStatement();
		ResultSet rec = st.executeQuery(sql.toString());
		if (rec.next()) {
			setSite(rec.getString("STIDAW"));
			setItem(rec.getString("ITNOAW"));
			setRevision(rec.getString("ITRVAW"));
			setAccountNumber(rec.getString("ACCTAW"));
			setAllowableDaysEarly(rec.getString("ALDEAW"));
			setAlphaFactor(rec.getString("ALPHAW"));
			setBuyer(rec.getString("BUYRAW"));
			setExtendedDescription1(rec.getString("PID1AW"));
			setExtendedDescription2(rec.getString("PID2AW"));
			setNature(rec.getString("CHGNAW"));
			setPreApprovedItem(rec.getString("PRAPAW"));
			setPurchasedItemCommodityClass(rec.getString("CMCLAW"));
			setPurchasePrice(rec.getString("PUPRAW"));
			setReceiptRequired(rec.getString("RCRQAW"));
			setShipVia(rec.getString("VIACAW"));
			setTolerancePercentReceivingNegative(rec.getString("TPRNAW"));
			setTolerancePercentReceivingPositive(rec.getString("TPRPAW"));
			setWeightedDeliveryPercent(rec.getString("WDLPAW"));
			setWeightedEarlyDeliveryPercent(rec.getString("WEDPAW"));
			setWeightedLateDeliveryPercent(rec.getString("WLDPAW"));
			setWeightedLeadTimePercent(rec.getString("WLTPAW"));
			setWeightedOvershipPercent(rec.getString("WOSPAW"));
			setWeightedPricePercent(rec.getString("WPRPAW"));
			setWeightedQualitiyPercent(rec.getString("WQUPAW"));
			setWeightedUndershipPercent(rec.getString("WUSPAW"));
		}
		rec.close();
		st.close();
		Factory.freeConnection(conn);
	}


	public void setAccountNumber(String accountNumber) {
		this.accountNumber = accountNumber;
	}


	public void setAllowableDaysEarly(String allowableDaysEarly) {
		this.allowableDaysEarly = allowableDaysEarly;
	}


	public void setAlphaFactor(String alphaFactor) {
		this.alphaFactor = alphaFactor;
	}


	public void setBuyer(String buyer) {
		this.buyer = buyer;
	}


	public void setExtendedDescription1(String extendedDescription1) {
		this.extendedDescription1 = extendedDescription1;
	}


	public void setExtendedDescription2(String extendedDescription2) {
		this.extendedDescription2 = extendedDescription2;
	}


	public void setItem(String item) {
		this.item = item;
	}


	public void setNature(String nature) {
		this.nature = nature;
	}


	public void setPreApprovedItem(String preApprovedItem) {
		this.preApprovedItem = preApprovedItem;
	}


	public void setPurchasedItemCommodityClass(String purchasedItemCommodityClass) {
		this.purchasedItemCommodityClass = purchasedItemCommodityClass;
	}


	public void setPurchasePrice(String purchasePrice) {
		this.purchasePrice = purchasePrice;
	}


	public void setReceiptRequired(String receiptRequired) {
		this.receiptRequired = receiptRequired;
	}


	public void setRevision(String revision) {
		this.revision = revision;
	}


	public void setShipVia(String shipVia) {
		this.shipVia = shipVia;
	}


	public void setSite(String site) {
		this.site = site;
	}


	public void setTolerancePercentReceivingNegative(
			String tolerancePercentReceivingNegative) {
		this.tolerancePercentReceivingNegative = tolerancePercentReceivingNegative;
	}


	public void setTolerancePercentReceivingPositive(
			String tolerancePercentReceivingPositive) {
		this.tolerancePercentReceivingPositive = tolerancePercentReceivingPositive;
	}


	public void setWeightedDeliveryPercent(String weightedDeliveryPercent) {
		this.weightedDeliveryPercent = weightedDeliveryPercent;
	}


	public void setWeightedEarlyDeliveryPercent(String weightedEarlyDeliveryPercent) {
		this.weightedEarlyDeliveryPercent = weightedEarlyDeliveryPercent;
	}


	public void setWeightedLateDeliveryPercent(String weightedLateDeliveryPercent) {
		this.weightedLateDeliveryPercent = weightedLateDeliveryPercent;
	}


	public void setWeightedLeadTimePercent(String weightedLeadTimePercent) {
		this.weightedLeadTimePercent = weightedLeadTimePercent;
	}


	public void setWeightedOvershipPercent(String weightedOvershipPercent) {
		this.weightedOvershipPercent = weightedOvershipPercent;
	}


	public void setWeightedPricePercent(String weightedPricePercent) {
		this.weightedPricePercent = weightedPricePercent;
	}


	public void setWeightedQualitiyPercent(String weightedQualitiyPercent) {
		this.weightedQualitiyPercent = weightedQualitiyPercent;
	}


	public void setWeightedUndershipPercent(String weightedUndershipPercent) {
		this.weightedUndershipPercent = weightedUndershipPercent;
	}

}